![I tried creating a RestAPI using AWS Lambda and API Gateway](https://devio2023-media.developers.io/wp-content/uploads/2023/08/amazon-api-gateway.png)
I tried creating a RestAPI using AWS Lambda and API Gateway
Introduction
Hello, Hemanth from the Alliance Department here. In this blog, I will walk you through my experience of creating a REST API using AWS Lambda and API Gateway.
AWS
Is a secure cloud service platform that offers compute power, database storage, content delivery, network, and other functionality to help businesses scale and grow. It is one of the first cloud vendors to start services in the year 2006. It offers all the 3 service models namely IAAS, PAAS, and SAAS. Some of the notable domains in AWS are Compute, Migration, Storage, Network and Content Delivery, Management Tools, Database, Messaging, Security and Identity Compliance, and many more.
API
It stands for Application Program interface which helps in connection of two applications, computers, or between computer programs to talk to each other. It is used to access data, server software, or other applications and has been around for some time. Each time anyone uses a particular app for weather updates or good restaurants in an app API is used.
RestAPI
A web service interface known as a REST API (Representational State Transfer Application Programming Interface) allows users to interact with resources denoted by URIs via HTTP methods like GET, POST, PUT, and DELETE. Its client-server architecture, which is stateless, guarantees that every request has all the information needed. Resources can be expressed in XML or JSON forms. Scalability, adaptability, and efficiency in online communication are the main goals of REST API architecture.
API Gateway
A fully managed service that makes developers easily create, publish, maintain, monitor, and secure APIs at any scale. API Gateway can be used to create Restful APIs and WebSocket APIs which have real-time two-way communication applications. It is a front door for applications to access data, business logic, or functionality from your backend services.
AWS Lambda
A serverless compute service which runs code as a reply to events and automatically takes care of the bottom resources. It runs code on high availability compute infrastructure and performs all the administration of the compute resources. A few examples are HTTP requests via Amazon API Gateway, changes to objects in S3, and many others.
Demo
Go to the AWS Management Console and navigate to Lambda. Click on "Create function," give it a name, set the runtime to Python, and click "Create function."
Lambda Function successfully created. Modify the function's content and click "Deploy".
Lambda function is successfully updated
Next in the AWS Management Console, select API Gateway and click on "Create API".
Choose API Type that is selecting "REST API" and click on "Build".
Give the API a name and leave other settings as default and click on "Create API".
Click on "Create Method"
Select GET as the method type, and set the integration type to Lambda Function. Choose the Lambda function created earlier.
Keep other settings as default and select "Create Method".
These steps grant the necessary permissions for the API Gateway to invoke the Lambda function.
Testing the API, Click on "DeployAPI".
choose a new stage, provide a stage name, and click "Deploy".
API has been deployed.
Copy the invoke URL to test the API.
The REST API has been successfully created and deployed.
Conclusion
Creating a REST API using AWS Lambda and API Gateway is a straightforward process that leverages the power of serverless computing and managed API services. By following the steps outlined in this blog, you can efficiently set up a scalable and cost-effective REST API. This integration allows for seamless management of backend services, reducing overhead and enabling rapid development.